This page has been superceded by a wiki version of this example: TwelveDaysOfChristmasExampleTwo
/*
The Twelve Days of Christmas
File: twelve_days_2.d
Author: Justin C. Calvarese, http://jcc_7.tripod.com/d/
Modified by: Larry Cowan
License: Public Domain
Produces the lyrics of the 12 Days of Christmas (all twelve verses)
*/
const char[] I1 = "On the ";
const char[] I2 = " day of Christmas, my true love gave to me:";
const char[] D1 = "A Partridge in a Pear Tree.";
const char[] D2 = "Two Turtle Doves, and";
const char[] D3 = "Three French Hens,";
const char[] D4 = "Four Calling Birds,";
const char[] D5 = "Five Golden Rings,";
const char[] D6 = "Six Geese a Laying,";
const char[] D7 = "Seven Swans a Swimming,";
const char[] D8 = "Eight Maids a Milking,";
const char[] D9 = "Nine Ladies Dancing,";
const char[] D10 = "Ten Lords a Leaping,";
const char[] D11 = "Eleven Pipers Piping,";
const char[] D12 = "Twelve Drummers Drumming,";
void println(char[] s)
{
printf(cast(char*) (s ~ "\n\0")); /* A simple \n\0 (without quotes) is valid in D, but d2html won't handle it */
}
int main (char[][] args)
{
char[] s;
for (int e=1; e<=12; e++)
{
s = I1;
switch(e) /* ...keeping the cases separate... */
{
case 1: s ~= "first"; break;
case 2: s ~= "second"; break;
case 3: s ~= "third"; break;
case 4: s ~= "fourth"; break;
case 5: s ~= "fifth"; break;
case 6: s ~= "sixth"; break;
case 7: s ~= "seventh"; break;
case 8: s ~= "eighth"; break;
case 9: s ~= "ninth"; break;
case 10: s ~= "tenth"; break;
case 11: s ~= "eleventh"; break;
default: s ~= "twelveth"; break;
}
s ~= I2;
println(s);
switch (e) /* ...and without the break statements... */
{
case 12: println(D12);
case 11: println(D11);
case 10: println(D10);
case 9: println(D9);
case 8: println(D8);
case 7: println(D7);
case 6: println(D6);
case 5: println(D5);
case 4: println(D4);
case 3: println(D3);
case 2: println(D2);
default: println(D1); println(""); break;
}
}
return 0;
}